//
//  BmobOperation.m
//  WonderfulNotes
//
//  Created by 千锋 on 16/1/18.
//  Copyright © 2016年 andy. All rights reserved.
//

#import "BmobOperation.h"
#import <BmobSDK/Bmob.h>
@implementation BmobOperation

+(void)addNoteToNoteTable:(NSString *)tableName noteTitle:(NSString *)noteTitle noteText:(NSString *)noteText noteImageUrl:(NSArray *)noteImageUrl  todo:(void(^)(BOOL isSuccessful,NSError *error)) todo{
    
    BmobObject * myNote = [BmobObject objectWithClassName:tableName];
    
   // [myNote setObject:userId forKey:@"userId"];
    [myNote setObject:noteTitle forKey:@"noteTitle"];
    [myNote setObject:noteText forKey:@"noteText"];
    [myNote setObject:noteImageUrl forKey:@"noteImage"];
    
    [myNote saveInBackgroundWithResultBlock:todo];

}

+(void)deleteNoteFromDatabase:(NSString *)tableName noteId:(NSString *)noteId{
    
    BmobQuery * delete = [BmobQuery queryWithClassName:@"Note"];
    
    [delete getObjectInBackgroundWithId:noteId block:^(BmobObject *object, NSError *error) {
       
        if (error) {
            
            NSLog(@"查询错误:%@",error);
            
        }else{
            
            if (object) {
                
                [object deleteInBackground];
                
            }
        }

    }];

}

@end
